/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SortingThreads;
import Sorting.Main;
import javax.media.j3d.BranchGroup;
import javax.swing.JOptionPane;

/**
 *
 * @author rafael
 */
public class QuickInPlaceThread extends Thread {

    public QuickInPlaceThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        execute();
    }

    private void execute() {

        try {

            //Main.textPane.setPreferredSize(new Dimension(500, 300));
            Main.textPane.setText(Main.textoQuick);
            BranchGroup bgroup = Main.addBranchGroup();
            Main.su.addBranchGraph(bgroup);


            System.out.println();
            System.out.println("Start = " + Main.start + "\nEnd = " + Main.end);

            System.out.print("Começo {");
            for(int i = 0; i < Main.vetorNumeros.length; i++){
                System.out.print(" " + Main.vetorNumeros[i].getNumber());
            }
            System.out.println(" }");
//            Main.quickInPlace(Main.vetorNumeros, Main.start, Main.end);
            Main.inPlaceQuickSort(Main.vetorNumeros, 0, Main.vetorNumeros.length - 1);
            JOptionPane.showMessageDialog(null, "A ordenação foi concluída!");

            Main.sc.show(Main.frame);

            Main.removeElements(Main.vetorNumeros);
            
            System.out.print("Fim: {");
            for(int i = 0; i < Main.vetorNumeros.length; i++){
                System.out.print(" " + Main.vetorNumeros[i].getNumber());
            }
            System.out.println(" }");

        } catch (NumberFormatException ex) {
                Main.removeElements(Main.vetorNumeros);
            
            
        } finally {
            Main.isRunning = false;
            Main.clearTexts();
            Main.trace = 0;
        }
    }
}
